<?php
include "../site_specific/project.php";
include "../includes/constants.php";
include "../site_specific/external_constants.php";
include "../includes/phpmailer/class.phpmailer.php";
include "../includes/phpmailer/class.smtp.php";
include "../includes/utilities.php";
include "../includes/pages.php";
include "../includes/database.php";
include "../includes/users.php";
include "../includes/date.php";
include "../includes/text.php";
include "../includes/files.php";

# Establish database connection
establishDatabaseConnection();

$get_flag = $_GET["flag"];

$get_tags = $_GET["tag"];

$get_blog = $_GET["blog"];

$update_sql = "";

$blog_select_sql ="SELECT b_index FROM ".$PROJECT_DB_TABLES["blogs"]." WHERE b_id=\"".$get_blog."\"";

$tag_select_sql = "SELECT t_index FROM ".$PROJECT_DB_TABLES["tags"]." WHERE t_tag=\"".$get_tags."\"";

$blogname = getRecord($blog_select_sql);

$tagname = getRecord($tag_select_sql);

if($get_flag == 'false'){

	$update_sql = "Delete FROM ".$PROJECT_DB_TABLES["blogtag"]." WHERE bt_blog=\"".$blogname[0]["b_index"]."\" AND bt_tag=\"".$tagname[0]["t_index"]."\"";
}
else if($get_flag == 'true'){

	$update_sql = "Insert INTO ".$PROJECT_DB_TABLES["blogtag"]." (bt_blog,bt_tag) VALUES ('".$blogname[0]["b_index"]."','".$tagname[0]["t_index"]."')";
}

if(executeSQLQuery($update_sql)){
	if($get_flag == 'false'){
		echo $update_sql;//"you have successfully cancel tag";
	}
	else{
		echo $update_sql;//"you have successfully add tag";
	}
}
//echo $tmp;
?>